<?php
session_start();
include_once("config.php");
checkLoggedIn("yes");

?>
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php print $title; ?></title>
</head>
<style type="text/css">
<!--
@import url("style.css");
-->
</style>
<body>
<?php

echo "<div class=\"body\">";
doCSS();
print("Bienvenido:  <b>".$_SESSION["login"]."</b><br>\n");
print("<a href=\"logout.php"."\">Logout</a><br>");
print("<a href=\"c_password.php"."\">Cambio de clave</a><br>");

if ( isset($_POST["mail"]) )
{
	$sql = "UPDATE ".$tabla_user." SET e_mail='".$_POST["mail"]."' WHERE user_id = '".$_SESSION["login"]."'";
        if ( !mysql_query($sql,$link) ) die('Error: ' . mysql_error());
}
if ( isset($_POST["twitter"]) )
{
        $sql = "UPDATE ".$tabla_user." SET twitter_id='".$_POST["twitter"]."' WHERE user_id = '".$_SESSION["login"]."'";
        if ( !mysql_query($sql,$link) ) die('Error: ' . mysql_error());
}
if ( isset($_POST["tracking_del"]) )
{
        $sql = "DELETE FROM ".$tabla_tracking." WHERE user_id = '".$_SESSION["login"]."' AND trk = '".$_POST["tracking_del"]."'";
        if ( !mysql_query($sql,$link) ) die('Error: ' . mysql_error());
	$sql = "DELETE FROM ".$tabla_data." WHERE trk = '".$_POST["tracking_del"]."'";
        if ( !mysql_query($sql,$link) ) die('Error: ' . mysql_error());
}
if ( isset($_POST["tracking_add"]) && isset($_POST["descripcion"]) )
{
        $sql = "INSERT INTO ".$tabla_tracking." (user_id,trk,comentario) VALUES ('".$_SESSION["login"]."','".$_POST["tracking_add"]."','".$_POST["descripcion"]."')";
        if ( !mysql_query($sql,$link) ) die('Error: ' . mysql_error());
}

echo "<br>";
echo "<br><div class=\"titulo\">Insertar trackings</div>";
echo "<form action=\"members.php\" method=\"post\">";
echo "Tracking -> <input type=\"text\" name=\"tracking_add\" > Descripcion -> <input type=\"text\" name=\"descripcion\" > <input type=\"submit\" value=\"Insertar\" /> </form>";

echo "<br>";
echo "<br><div class=\"titulo\">Actualizacion de E-Mail / Twitter</div>";
$result = mysql_query("SELECT * from ".$tabla_user." where user_id ='".$_SESSION["login"]."'", $link);
$numlineas = mysql_num_rows($result);
echo "E-Mail  -> ".mysql_result($result,0,"e_mail")."<br>";
echo "<form action=\"members.php\" method=\"post\">";
echo "E-Mail  -> <input type=\"text\" name=\"mail\"> <input type=\"submit\" value=\"Actualizar\" /> </form><br>";
echo "Twitter -> ".mysql_result($result,0,"twitter_id")."<br>";
echo "<form action=\"members.php\" method=\"post\">";
echo "Twitter -> <input type=\"text\" name=\"twitter\"> <input type=\"submit\" value=\"Actualizar\" /> </form><br>";

echo "<br><div class=\"titulo\">Listado de trackings</div>";
echo "<table id=\"hor-minimalist-b\" summary=\"Detalle pagos\">";
echo "<thead><tr><th scope=\"col\">Tracking</th><th scope=\"col\">Descripcion</th><th scope=\"col\">Fecha de ingreso</th><th scope=\"col\">Borrar</th><th scope=\"col\">Ver cache</th></tr></thead>";
echo "<tbody>";

$result = mysql_query("SELECT * from ".$tabla_tracking." where user_id ='".$_SESSION["login"]."'", $link);
$numlineas = mysql_num_rows($result);

for ($linea = 0; $linea < $numlineas ; $linea++)
{
	echo "<tr>";
	echo "<td>".mysql_result($result,$linea,"trk")."</td><td>".mysql_result($result,$linea,"comentario")."</td><td>".mysql_result($result,$linea,"date")."</td>";
	echo "<td><form action=\"members.php\" method=\"post\"><input type=\"hidden\" name=\"tracking_del\" value=\"".mysql_result($result,$linea,"trk")."\" /><input type=\"image\" src=\"delete-icon.png\" width=\"15\" height=\"15\" /> </form></td>";
	echo "<td><form action=\"cache.php\" method=\"post\"><input type=\"hidden\" name=\"cache_trk\" value=\"".mysql_result($result,$linea,"trk")."\" /><input type=\"image\" src=\"check-icon.png\" width=\"15\" height=\"15\" /> </form></td>";
	echo "</tr>";

}
echo "</tbody>";
echo "</table>";

echo "<br><div class=\"titulo\">Ver resultados en Correo Argentino</div>";
print("<a href=\"online.php"."\">Resultados en correo</a><br>");

echo "</div>";
?>
</body>
</html>
